package com.hibase.core.mq.factory;

import com.hibase.core.mq.annotation.HibaseQueue;
import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

/**
 */
@Slf4j
public enum QueueWrapperFactory {
    INSTANCE;

    private Map<Class<? extends Annotation>,QueueWrapper> cachedWrappers = new HashMap<>();

    QueueWrapperFactory(){
        cachedWrappers.put(HibaseQueue.class,new HibaseQueueWrapper());
    }

    public QueueWrapper instance(String clzName) throws Exception{
        Class clz = Class.forName(clzName);
        return instance(clz);
    }

    public QueueWrapper instance(Class<?> clz) throws Exception{
        if(clz.isAnnotationPresent(HibaseQueue.class)){
            return cachedWrappers.get(HibaseQueue.class);
        }else{
            log.error("No Queue Annotation on Class [{}], please check your configuration.",clz.getName());
            throw new NullPointerException("No Queue Annotation on Class [" + clz.getName() + "], please check your configuration.");
        }
    }
}
